﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


//所有能放到场景中的物体的积累
//提供 配置 位置等功能
public abstract class SceneObject : MonoBehaviour 
{

    public UnityEngine.Sprite icon;
    public string Name;

    void Awake()
    {
        Init();
    }

	// Use this for initialization
	void Start () 
    {
        StartCoroutine(UpdateCo());
	}
	
	// Update is called once per frame
	void Update () 
    {
	    	
	}

    float lastupdateTime = -1.0f;

    IEnumerator UpdateCo()
    {
        while(true)
        {
            yield return new WaitForSeconds(0.1f);
            float thistime = Time.time;
            float updateTime = 0.1f;
            if(lastupdateTime == -1.0f)
            {
                lastupdateTime = thistime;
            }
            else
            {
                updateTime = thistime - lastupdateTime;
                lastupdateTime = thistime;
            }
            UpdateWrap(updateTime);
        }
    }

    protected int _x;
    protected int _y;
    protected float _temperature;

    public void SetPosition(int x,int y)
    {
        _x = x;
        _y = y;
        transform.position = new Vector2(x + 0.5f,y + 0.5f);
    }

    public abstract void Init();

    public abstract int GetWidth();

    public abstract int GetHeight();

    public abstract float GetMass();

    public abstract void UpdateWrap(float deltaTime);

    public virtual void UpdatePerFrame()
    {

    }
}
